﻿using Common;
using DadayunApi.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace DadayunApi
{
    public partial class IMApi:Api
    {
        public IMApi(AppAuthBase authBase, string baseUri) : base(authBase, baseUri)
        {
        }

        /// <summary>
        ///  获取用户token
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="nickName">用户昵称，如果未注册到融云服务器，第一次获取必填</param>
        /// <param name="portraitUri">用户头像URI，同name</param>
        /// <param name="refresh">是否强制刷新token（即刷新bpm后端的缓存，重新到融云服务器获取一次）</param>
        /// <returns></returns>
        public string GetUserToken(string userId,string nickName=null,string portraitUri=null,bool refresh=false)
        {
            var uri = "/v1/im/users/"+userId+"/token" ;
            string cond = "?refresh="+ refresh;
            if (!string.IsNullOrEmpty(nickName)) cond += "&name=" + nickName;
            if (!string.IsNullOrEmpty(portraitUri)) cond += "&portraitUri=" + portraitUri;
            uri += cond;
            httpStatus = HttpGet(uri);
            
            return responseJson;
        }
    }
}
